// 移动 0 到数组末尾

function moveZero(arr: number[]): void {
    const length = arr.length;
    if (length === 0) return;
    let zeroLength = 0;
    for (let i = 0; i < length - zeroLength; i++) {
        if (arr[i] === 0) {
            arr.push(0);
            arr.splice(i, 1);
            i--;
            zeroLength++;
        }
    }
}

function moveZero1(arr: number[]): void {
    const length = arr.length;
    if (length === 0) return;
    let i;
    let j = -1;
    for (i = 0; i < length; i++) {
        if (arr[i] === 0) {
            if (j < 0) {
                j = i
            }
        }
        if (arr[i] !== 0 && j >= 0) {
            const n = arr[i];
            arr[i] = arr[j];
            arr[j] = n
            j++
        }
    }

}
const arr = [0, 1, 3, 0, 4, 5, 0]
moveZero1(arr)
console.log(arr);
